package flc.ast.adapter;


import android.view.View;
import android.widget.ImageView;

import androidx.annotation.NonNull;

import com.bumptech.glide.Glide;
import com.chad.library.adapter.base.provider.BaseItemProvider;
import com.chad.library.adapter.base.viewholder.BaseViewHolder;

import flc.ast.R;
import flc.ast.bean.MyAlbumBean;
import stark.common.basic.adaptermutil.StkProviderMultiAdapter;
import stark.common.basic.adaptermutil.StkSingleSpanProvider;

public class AlbumAdapter extends StkProviderMultiAdapter<MyAlbumBean> {


    public AlbumAdapter() {
        addItemProvider(new StkSingleSpanProvider(126));
        addItemProvider(new AlbumProvider());
    }

    private boolean isEdit = false;

    public void setEdit(boolean edit) {
        isEdit = edit;
        notifyDataSetChanged();
    }

    private class AlbumProvider extends BaseItemProvider<MyAlbumBean> {
        @Override
        public int getItemViewType() {
            return StkProviderMultiAdapter.TYPE_VIEW;
        }

        @Override
        public int getLayoutId() {
            return R.layout.item_album;
        }

        @Override
        public void convert(@NonNull BaseViewHolder baseViewHolder, MyAlbumBean bean) {
            baseViewHolder.setText(R.id.tvAlbumItemName, bean.getName());
            int size = bean.getListData().size();
            baseViewHolder.setText(R.id.tvAlbumItemSize, size + "");
            if (size == 0) {
                baseViewHolder.getView(R.id.rlAlbumItemImg).setVisibility(View.GONE);
                baseViewHolder.getView(R.id.ivAlbumItemNoImg).setVisibility(View.VISIBLE);
            } else {
                baseViewHolder.getView(R.id.rlAlbumItemImg).setVisibility(View.VISIBLE);
                baseViewHolder.getView(R.id.ivAlbumItemNoImg).setVisibility(View.GONE);
                if (size >= 1) {
                    Glide.with(baseViewHolder.itemView).load(bean.getListData().get(0)).into((ImageView) baseViewHolder.getView(R.id.ivAlbumItemImg1));
                    baseViewHolder.getView(R.id.rlAlbumItemImg2).setVisibility(View.GONE);
                    baseViewHolder.getView(R.id.rlAlbumItemImg3).setVisibility(View.GONE);
                }
                if (size >= 2) {
                    Glide.with(baseViewHolder.itemView).load(bean.getListData().get(1)).into((ImageView) baseViewHolder.getView(R.id.ivAlbumItemImg2));
                    baseViewHolder.getView(R.id.rlAlbumItemImg2).setVisibility(View.VISIBLE);
                    baseViewHolder.getView(R.id.rlAlbumItemImg3).setVisibility(View.GONE);
                }
                if (size >= 3) {
                    Glide.with(baseViewHolder.itemView).load(bean.getListData().get(2)).into((ImageView) baseViewHolder.getView(R.id.ivAlbumItemImg3));
                    baseViewHolder.getView(R.id.rlAlbumItemImg2).setVisibility(View.VISIBLE);
                    baseViewHolder.getView(R.id.rlAlbumItemImg3).setVisibility(View.VISIBLE);
                }
            }
            if (isEdit) {
                baseViewHolder.getView(R.id.ivAlbumItemSel).setVisibility(View.VISIBLE);
                if (bean.isSelected()) {
                    baseViewHolder.setImageResource(R.id.ivAlbumItemSel, R.drawable.icon_gx2);
                }else {
                    baseViewHolder.setImageResource(R.id.ivAlbumItemSel, R.drawable.icon_gx3);
                }
            } else {
                baseViewHolder.getView(R.id.ivAlbumItemSel).setVisibility(View.INVISIBLE);
            }
        }
    }

}
